/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.siagefi.model;

import br.siagefi.interfaces.BaseEntity;
import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author NOTE
 */
@Entity
@Table(name = "conta")
@NamedQuery(name = "Conta.buscaPorBanco", query = "SELECT c FROM ContaBancaria c WHERE c.banco = ?1")
public class ContaBancaria extends Conta implements Serializable, BaseEntity{
    
      @ManyToOne
    private Banco banco;
    
    @Column(name = "agencia", length = 50)
    private String agencia;
    
    @Column(name = "numero_agencia", length = 6)
    private int numeroAgencia;
    
    @Column(name = "numero_conta_bancaria", length = 12)
    private int numeroContaBancaria;
    
    @Column(name = "gerente", length = 30)
    private String gerente;
    
    public ContaBancaria() {
       super();
    }

    public Banco getBanco() {
        return banco;
    }

    public void setBanco(Banco banco) {
        this.banco = banco;
    }

    public String getAgencia() {
        return agencia;
    }

    public void setAgencia(String agencia) {
        this.agencia = agencia;
    }

    public int getNumeroAgencia() {
        return numeroAgencia;
    }

    public void setNumeroAgencia(int numeroAgencia) {
        this.numeroAgencia = numeroAgencia;
    }

    public int getNumeroContaBancaria() {
        return numeroContaBancaria;
    }

    public void setNumeroContaBancaria(int numeroContaBancaria) {
        this.numeroContaBancaria = numeroContaBancaria;
    }

    public String getGerente() {
        return gerente;
    }

    public void setGerente(String gerente) {
        this.gerente = gerente;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 43 * hash + Objects.hashCode(this.getNome());
        hash = 43 * hash + Objects.hashCode(this.getDataAbertura());
        hash = 43 * hash + Objects.hashCode(this.banco);
        hash = 43 * hash + this.numeroAgencia;
        hash = 43 * hash + this.numeroContaBancaria;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ContaBancaria other = (ContaBancaria) obj;
        if (!Objects.equals(this.getNome(), other.getNome())) {
            return false;
        }
        if (!Objects.equals(this.getDataAbertura(), other.getDataAbertura())) {
            return false;
        }
        if (!Objects.equals(this.banco, other.banco)) {
            return false;
        }
        if (this.numeroAgencia != other.numeroAgencia) {
            return false;
        }
        if (this.numeroContaBancaria != other.numeroContaBancaria) {
            return false;
        }
        return true;
    }

    public void atualizaSaldo(double valor, String tipo) {
        double saldo = this.getSaldo();
        if(tipo.equals("DEBITO")){
            saldo = saldo - valor;
        }else {
            saldo = saldo + valor;
        }
        this.setSaldo(saldo);
    }
    
}
